// pkgA/editFish/editFish.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 单选框属性
        radio: '',

        //更新鱼属性
        aquariumId: Number,
        id: '',
        name: '',
        age: Number,
        type: '',
        state: '',
        illType: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            aquariumId: options.aquariumId,
            id: options.id,
            name: options.fishName,
            age: options.age,
            type: options.type,
            state: options.state,
            illType: options.illType
        })

        if (options.state == '良好') {
            this.setData({
                state: '良好',
                radio: '良好'
            })
        } else if (options.state == '生病') {
            this.setData({
                state: '生病',
                radio: '生病'
            })
        } else {
            this.setData({
                state: '死亡',
                radio: '死亡'
            })
        }
    },

    //双向绑定名字输入
    setName(e) {
        this.setData({
            name: e.detail.value
        })
    },
    setAge(e) {
        this.setData({
            age: e.detail.value
        })
    },
    setType(e) {
        this.setData({
            type: e.detail.value
        })
    },
    onChange(e) {

        this.setData({
            radio: e.detail,
            state: e.detail
        })

    },
    setillType(e) {
        this.setData({
            illType: e.detail.value
        })
    },

    submit() {

        wx.request({
            url: 'http://120.77.156.205:8808/wx/aquarium/editFish',
            data: {
                aquariumId: this.data.aquariumId,
                id: this.data.id,
                name: this.data.name,
                inAge: this.data.age,
                type: this.data.type,
                state: this.data.state,
                illType: this.data.illType
            },
            method: 'POST',
            success: (res) => {
                if (res.data.code == 11) {
                    wx.showToast({
                        title: '昵称已存在！',
                        icon: "error",
                        duration: 1500
                    })
                    return
                }
                if (res.data.code == 1) {
                    wx.showToast({
                        title: '修改失败！',
                        icon: "error",
                        duration: 1500
                    })
                    return
                }
                if (res.data.code == 0) {
                    wx.showToast({
                        title: '修改成功！',
                        icon: 'success',
                        duration: 15000
                    })
                    wx.reLaunch({
                      url: '../../pages/index/index?selectIndex=2',
                    })
                }

            },
            fail:()=>{
                wx.showToast({
                    title: '修改失败！',
                    icon: "error",
                    duration: 1500
                })
                return
            }
        })


    }



})